<?
$errorMsg = '';
$okMsg = '';
/*
if($reg_domain_success == 'yes'){
        if(!add_domain_mailbox_email($id,$domain4registration,$mailbox_pass)){
                $errorMsg = translate('error_creating_domain_mailbox');
        }
        $okMsg = translate('reg_domain_success');
}else
*/
if($whois_changed == 'yes'){
        if($_GET[errorMsg]!='{details_changed}'){
                $errorMsg = translate(substr($_GET[errorMsg],1,strlen($_GET[errorMsg])-2));
        }else{
                $okMsg = translate(substr($_GET[errorMsg],1,strlen($_GET[errorMsg])-2));
        }
        $okMsg = translate('whois_changed');
}elseif($dns_changed == 'yes'){
        if($_GET[errorMsg]!='{dns_changed}'){
                $errorMsg = translate(substr($_GET[errorMsg],1,strlen($_GET[errorMsg])-2));
        }else{
                $okMsg = translate(substr($_GET[errorMsg],1,strlen($_GET[errorMsg])-2));
        }
}elseif($_SESSION['order']){
	if(in_array($_SESSION['order']['domain_action'], array('register','transfer'))){
	        if(!add_domain_mailbox_email($GLOBALS['id'], $_SESSION['order']['domain'], $_SESSION['order']['pass'])){
        	        $errorMsg = translate('error_creating_domain_mailbox');
		}
	}

//res_regdomain_order
//res_regdomain_renewal
//dns_package_order
//dns_package_renewal

	if(!$errorMsg){
		$okMsg = translate($_SESSION['order']['type'].'_'.$_SESSION['order']['action'].'_'.$_SESSION['order']['domain_action'].'_success');
	}

	unset($_SESSION['order']);
}

?>

<html>
<head>
<link rel="stylesheet" href="domain/styles_domain.css" type="text/css">
<script>
var current_domain = '';
var selected_tab = 'reg_dom_';
var selected_tab_div = 'reg_dom';
var current_tooltip_div = '';
var currentTab = 'myDomains';
/****************************************************************************************************/

function fSubmit(form_url,param){
	document.sform.action = form_url;
	document.sform.add_param.value = param;
	document.sform.submit();
}
/****************************************************************************************************/

function confirmSubmit(msg){
	var agree = confirm(msg);
	if (agree){
		return true;
	}else{
		return false;
	}
}
/****************************************************************************************************/

function tooltip_action(display,id){
	if(document.getElementById(current_tooltip_div)){
		if(display == 'block'){
			document.getElementById(current_tooltip_div).style.display = 'none';
			document.getElementById(id).style.display = display;
		} else if(display == 'none'){
			document.getElementById(current_tooltip_div).style.display = 'block';
			if(id != current_tooltip_div){
				document.getElementById(id).style.display = display;
			}
		}
	}else {
		if(display == 'block'){
			document.getElementById(id).style.visibility = 'visible';
		}else if(display == 'none'){
			document.getElementById(id).style.visibility = 'hidden';
		}
	}
}
/****************************************************************************************************/

function showVAT(selectBoxVAT) {
	if (typeof(selectBoxVAT) == 'string') {
		var vatSelect = document.getElementById(selectBoxVAT);
		var optionSelect = document.getElementById(vatSelect.value);

		if (optionSelect.labela == 1) {
			showHide (true, 'vat_radio');
			showHide (true, 'vat_text');
			showVatNum (true);
                } else {
			showHide (false, 'vat_radio');
			showHide (false, 'vat_text');
			showVatNum (false);
		}
	}
}
/****************************************************************************************************/

function showVatNum(show) {
	showHide (show, 'vat_input');
	showHide (show, 'vat_input1');
}
/****************************************************************************************************/

function checkCompany(formObject) {
	if (typeof(formObject) == 'undefined') {
		return false;
	}

	if (formObject.company_name.value == '') {
		formObject.vat_registered[0].click();
	}
}
/****************************************************************************************************/

function showHide (show, objectId) {
	if (typeof(objectId) == 'string') {
		var Box = document.getElementById(objectId);

		switch (show) {
			case true:
				Box.style.display = 'block';
			break;
			case false:
				Box.style.display = 'none';
			break;
		}
	}
}
/****************************************************************************************************/

var selected_domain = '';
function bold_this(id){
	if(selected_domain != '' && document.getElementById(selected_domain)){
		document.getElementById(selected_domain).className = 'Normal';
	}
	if(document.getElementById(id)){
		selected_domain = id;
		document.getElementById(selected_domain).className = 'Bold';
	}
}
/****************************************************************************************************/

function LoadPage(id, params){
	loadinga('<b>loading...</b>');
	xajax_myLoadPage(id, params);
	if(id != 'changeARecord' && id != 'changeRecords'){
		switchTab(id);
	}
}
/****************************************************************************************************/

function addDomain(){
	var id = '<? echo $GLOBALS['id']; ?>';
	var domain = document.getElementById('domain').value;
	var pass = document.getElementById('pass').value;
	var repass = document.getElementById('repass').value;
	loadinga('<b>processing...</b>');
	xajax_addDomain(id,domain,pass,repass);
}
/****************************************************************************************************/

function check_domain_pass(){
	var domain = document.getElementById('domain').value;
	var pass = document.getElementById('pass').value;
	var repass = document.getElementById('repass').value;

	if(! /^([a-z0-9][a-z0-9-]?)*[a-z0-9]\.([a-z]{2,4})(\.[a-z]{2,4})?$/.test(domain)){
		alert ('Invalid Domain Name');
		return false;
	}

	if(pass != repass){
		alert ('Passwords Don\'t Match');
		return false;
	}

	if(pass=='' && repass==''){
		alert ('Empty Password');
		return false;
	}

	return true;
}
/****************************************************************************************************/

function loadinga(text){
	//document.getElementById('load').innerHTML = text;
	document.getElementById('load').style.visibility = 'visible';
}
/****************************************************************************************************/

function show_ns_type(id){
	if(id == 'products1' || id == 'products2'){
		if(document.getElementById(id).checked == true && document.getElementById('dns_settings').style.display == 'none'){
			document.getElementById('dns_settings').style.display = 'block';
		}
	}else if(id == 'products3'){
		if(document.getElementById(id).checked == true && document.getElementById('dns_settings').style.display == 'block'){
			document.getElementById('dns_settings').style.display = 'none';
		}
	}
}
/****************************************************************************************************/

var focused = {'products':'','ns_type':''};
function selected_ns(obj){
	if(focused[obj.name] != '' && document.getElementById(focused[obj.name])){
		document.getElementById(focused[obj.name]).className = 'notselected_dns';
	}
	if(obj.value && document.getElementById('tbl_' + obj.value)){
		focused[obj.name] = 'tbl_' + obj.value;
		document.getElementById(focused[obj.name]).className = 'selected_dns';
	}
}
/****************************************************************************************************/

function appendResult (result, append){
	if(result == ''){
		return append;
	}

	var app = append.split('::');
	var res = result.split('|');
	var ret = '';
	var flag = false;

	for (var i = 0; i < res.length; i++){
		if(res[i].indexOf('|' + app[0] + '::') != -1 || res[i].substring(0,(app[0] + '::').length) == (app[0] + '::')){
			flag = true;
			res[i] = append;
		}
		ret = ret + '|' + res[i];
	}

	if(!flag){
		ret = ret + '|' + append;
	}

	//alert(result + '<>' + append + '<>' + ret.substring(1,ret.length));
	return ret.substring(1,ret.length);
}
/****************************************************************************************************/

function cleanFormElements(formElements, params){
	if(params == ''){
		return params;
	}

	var index = -1;
	var result = '|' + params + '|';
	var prepend = '';
	var append = '';
	for (var j=0; j < formElements.length; j++){
		index = result.indexOf('|' + formElements[j].name + '::');
		if(index != -1){
			prepend = result.substring(0, index);
			append = result.substring(index + 1);
			//alert('before -> ' + result);
			result = prepend + append.substring(append.indexOf('|'));
			//alert('after -> ' + result);
		}
	}

	result = result.substring(1);
	if(result.length > 0){
		result = result.substring(0, result.length - 1);
	}

	return result;
}
/****************************************************************************************************/
function fetchForm (){
	formElements = document.getElementById('sform').elements;
	var append = '';
	var result = '';

	if(document.getElementById('params') && document.getElementById('params').value != ''){
		result = cleanFormElements(formElements, document.getElementById('params').value);
	}

	for (var i=0; i < formElements.length; i++){
		if(formElements[i].id != 'params'){
			if(formElements[i].type=='text' || formElements[i].type=='password' || formElements[i].type=='hidden' || formElements[i].type=='textarea'){
				append = formElements[i].name + '::' + formElements[i].value;
				result = appendResult(result, append);
			}else if(formElements[i].type=='select-one' || formElements[i].type=='select-multiple'){
				for (var j = 0; j < formElements[i].options.length; j++){
					if(formElements[i].options[j].selected){
						append = formElements[i].name + '::' + formElements[i].options[j].value;
						result = appendResult(result, append);
					}
				}
			}else if((formElements[i].type=='checkbox' || formElements[i].type=='radio') && formElements[i].checked){
				append = formElements[i].name + '::' + formElements[i].value;
				result = appendResult(result, append);
			}
		}
	}

	return result;
}
/****************************************************************************************************/

function show_domain_tooltip(params){
	var dom_action = params.substring(0, params.indexOf('_'));
	var dom_name = params.substring((params.indexOf('_') + 1));
	tooltips_children = getChildList(document.getElementById('tooltips'));
	for(var i=0; i < tooltips_children.length; i++){
		//alert(tooltips_children[i].id + '<->' + 'tooltip_' + dom_action);
		if(tooltips_children[i].id != 'tooltip_' + dom_action){
			tooltips_children[i].style.display = 'none';
			//alert('hide: ' + tooltips_children[i].id + ' -> ' + tooltips_children[i].style.display);
		}else if(tooltips_children[i].id == 'tooltip_' + dom_action){
			tooltips_children[i].style.display = 'block';
			//alert('show: ' + tooltips_children[i].id + ' -> ' + tooltips_children[i].style.display);
		}
	}

	for(i=1; i < 5; i++){
		if(document.getElementById(('dom' + i))) {
			document.getElementById(('dom' + i)).innerHTML = dom_name;
		}
	}
	//document.getElementById(tooltip_available.dom_action);
	//alert(domain + '<->' + dom_action);
}
/****************************************************************************************************/

function show_ns_tooltip(val){
	if(val == 'p1' || val == 'p2'){
		document.getElementById('nmngdns').style.display = 'none';
		document.getElementById('mngdns').style.display = 'block';
	}else if(val == 'p3'){
		document.getElementById('mngdns').style.display = 'none';
		document.getElementById('nmngdns').style.display = 'block';
	}
}
/****************************************************************************************************/

function getChildList (obj){
	var count = obj.childNodes.length;
	var res = new Array();
	var j=0;
	for (var i=0; i<count; i++){
		if(obj.childNodes[i].nodeName != '#text'){
			res[j] = obj.childNodes[i];
			j++;
		}
	}
	return res;
}
/****************************************************************************************************/

function setPM(obj){
	var childList = getChildList(obj.parentNode.parentNode);
	for(var i = 0; i < childList.length; i++){
		span = childList[i];
		//alert('selected_' + obj.id + ' <-> ' + span.id);
		if('selected_' + obj.id == span.id){
			span.style.fontWeight = 'bold';
		}else{
			span.style.fontWeight = 'normal';
		}
	}
}

/****************************************************************************************************/

function Run (act, params){
	//var params = fetchForm();
//	alert(params);
	eval(act + '(params);');
}
/****************************************************************************************************/

function searchDomain(params){
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run('searchDomain', params);
}
/****************************************************************************************************/

function chooseDomain (params){
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run ('chooseDomain', params);
}
/****************************************************************************************************/

function choosePlan (params) {
//	alert(params);
	loadinga('<b>processing...</b>');
	if(document.getElementById('dns_features1') && document.getElementById('dns_features1').checked == true){
		params = params + '|mail_server::yes';
		params = params + '|open_store::yes';
		params = params + '|enabled::yes';
	}else if(document.getElementById('dns_features2') && document.getElementById('dns_features2').checked == true){
                params = params + '|mail_server::yes';
                params = params + '|enabled::yes';
	}else if(document.getElementById('dns_features3') && document.getElementById('dns_features3').checked == true){
                params = params + '|enabled::yes';
	}

	xajax_Run ('choosePlan', params);
}
/****************************************************************************************************/

function mailBox (params){
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run ('mailBox', params);
}
/****************************************************************************************************/

function Whois (params) {
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run ('Whois', params);
}
/****************************************************************************************************/

function choosePM (params) {
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run ('choosePM', params);
}
/****************************************************************************************************/

function delDomains (params) {
//        alert(params);
        loadinga('<b>processing...</b>');
        xajax_Run ('delDomains', params);
}
/****************************************************************************************************/

function submitPayment (params) {
//	alert(params);
	loadinga('<b>processing...</b>');
	xajax_Run ('submitPayment', params);
}
/****************************************************************************************************/

function domainDetails (params) {
//        alert(params);
        loadinga('<b>processing...</b>');
        xajax_Run ('domainDetails', params);
}
/****************************************************************************************************/

function loadPlan (plan_id){
	loadinga('<b>processing...</b>');
	xajax_myLoadPage('registerDomains', 'stepPage::Step1', 'products::' + plan_id);
	switchTab('registerDomains');
}
/****************************************************************************************************/

function goTransfer (dom){
        loadinga('<b>processing...</b>');
	var params = 'search_domain::example.com|domain::notavailable_' + dom;
	searchDomain(params);
	switchTab('registerDomains');
}
/****************************************************************************************************/

function goAddMNDS(params){
	chooseDomain(params);
	switchTab('registerDomains');
}
/****************************************************************************************************/

function renewalServices(params){
//        alert(params);
        loadinga('<b>processing...</b>');
        xajax_Run ('renewalServices', params);
	switchTab('registerDomains');
	//xajax_myLoadPage('registerDomains', 'stepPage::Step5', params);
	//switchTab('registerDomains');
}
/****************************************************************************************************/

function switchTab(newTab){
	if(currentTab != ''){
		document.getElementById(currentTab).className = 'notselected';
	}
	currentTab = newTab;
	document.getElementById(currentTab).className = 'selected';
}
/****************************************************************************************************/

function LoadDnsDomainInfo(params){
	loadinga('<b>processing...</b>');
//	LoadPage();
	xajax_Run ('LoadDnsDomainInfo', params);
}
/****************************************************************************************************/

function SelectEvent(select) {
	var value = select.options[select.selectedIndex].value;
	eval(value);
}
/****************************************************************************************************/

var store_ip = '';
function store_settings(checked){
	if(checked){
		store_ip = document.getElementById('store_a_record').value;
		document.getElementById('store_a_record').disabled = false;
	}else{
		document.getElementById('store_a_record').value = store_ip;
		document.getElementById('store_a_record').disabled = true;
	}
}
/****************************************************************************************************/

function change_store_settings(params){
//	alert(params);
        loadinga('<b>processing...</b>');
        xajax_Run ('change_store_settings', params);
}

/****************************************************************************************************/

function changeARecord(dns_dom_id){
	loadinga('<b>loading...</b>');
	LoadPage('changeRecords', 'dns_dom_id::' + dns_dom_id);
}
/****************************************************************************************************/

function addRecord(params){
//	alert(params);
	loadinga('');
	xajax_Run('addRecord', params);
}
/****************************************************************************************************/

function deleteRecord(params){
//	alert(params);
	loadinga('');
	xajax_Run('deleteRecord', params);
}
/****************************************************************************************************/

function editRecord(params){
//	alert(params);
	loadinga('');
	xajax_Run('editRecord', params);
}
</script>
</head>

<body>
<br>
<table cellspacing=0 cellpadding=0 width=100% class=myTable>
        <?

        if (isset($from_page)) {
                $paramsa[sid] = $sid;
                $paramsa[action] = "home";
                $urla = "$baseURL/$webDIR/?".encode_params($paramsa);
                echo "<tr><td align=right colspan=9><div style='padding: 4 4 4 4; text-align:right;'><a href='$urla'>&laquo; Back to Home</div></td></tr>";
        }
        ?>
	<tr>
		<td colspan=9 align=center>
			<div id='error' style='display:<? echo ($GLOBALS[errorMsg] ? 'block' : 'none'); ?>;'>
			<?
			include_once('errorMsg.html');
			?>
			</div>
			<div id='notice' style='display:<? echo ($GLOBALS[okMsg] ? 'block' : 'none'); ?>;'>
			<?
			include_once('okMsg.html');
			?>
			</div>
		</td>
	</tr>
	<tr>
		<td colspan=8 align=right>
			<div id='debug'></div>
			<div id='load' style='visibility: hidden; text-align: right;'><img src='domain/images/loading.gif' /></div>
		</td>
	</tr>
	<tr>
		<td width=5 class='blank'>&nbsp</td>
		<td id='myDomains' class='notselected' align=center onClick="LoadPage(this.id,'');"><b>My Domains</b></td>
		<td width=5 class='blank'>&nbsp</td>
		<td id='registerDomains' class='notselected' align=center onClick="LoadPage(this.id,'stepPage::Step1');"><b>Register/Transfer</b></td>
		<td width=5 class='blank'>&nbsp</td>
		<td id='existingDomains' class='notselected' align=center onClick="LoadPage(this.id,'');"><b>Use Existing</b></td>
		<td width=5 class='blank'>&nbsp</td>
		<td id='managednsDomains' class='notselected' align=center onClick="LoadPage(this.id,'');"><b>Private DNS</b></td>
		<td width=5 class='blank'>&nbsp</td>
	</tr>
	<tr>
		<td colspan=9 class=main>
			<div id='page'>
			</div>
			<div id="submitForm">
			</div>
		</td>
	</tr>
</table>

<script language="Javascript">
LoadPage(currentTab);
</script>
<?
if($GLOBALS['start_ajax']){
	echo '<script language="Javascript">';
	foreach($GLOBALS['start_ajax'] as $k => $v){
		echo "var timeout_$k = setTimeout(\"$v\",2000);";
	}
	echo '</script>';
	$query = "SELECT name, product_id FROM products WHERE reseller_id='$id' AND type='plan' AND name IN ('Business','Corporate')";
	$res = $GLOBALS['master_db']->query($query);
	//print_r($res);
}
?>
</body>
</html>